package com.scaffold.chapter.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wangjg.commons.page.Page;

import com.scaffold.chapter.dao.TopicDAO;
import com.scaffold.chapter.entity.Topic;

@Service
@Transactional
public class TopicService{

	@Autowired
	private TopicDAO topicDAO;

	public Topic getTopic(Long id ) {
		return this.topicDAO.findById(id);
	}

	public void save(Topic topic){
		Date now = new Date();
		if(topic.getId()==null){
			topic.setCreated(now);
			topic.setModified(now);
			this.topicDAO.save(topic);
		}else{
			topic.setModified(now);
			this.topicDAO.update(topic);
		}
	}

	public void update(Topic topic){
		Date now = new Date();
		topic.setModified(now);
		this.topicDAO.update(topic);
	}

	public void delete(Topic topic){
		this.topicDAO.delete(topic);

	}

	public void batchDelete(String idseq) {
		String[] sa = idseq.split(",");
		for(String s:sa){
			Long id = Long.parseLong(s);
			this.topicDAO.delete(id);

		}
	}
	

	public List<Topic> pageQuery(Page page, String name, String keyword) {
		return this.topicDAO.pageQuery(page, name, keyword);
	}


}
